package Offer;
/*
* 树的子结构   双递归
* */
public class Offer26isSubStructure {
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if(A==null && B==null){
            return true;
        }
        if(A==null || B==null){
            return false;
        }
        return dfs(A,B) || isSubStructure(A.left,B) || isSubStructure(A.right,B);
    }

    private boolean dfs(TreeNode a, TreeNode b) {
        if(b==null){
            return true;
        }
        if(a==null){
            return false;
        }
        if(a.val==b.val){
            return dfs(a.left,b.left) && dfs(a.right,b.right);
        }else{
            return false;
        }
    }
}
